<template>
	<el-form size="large" class="login-content-form">
		<el-form-item class="login-animation1">
			<el-input type="text" placeholder="请输入账号" v-model="ruleForm.userName" clearable autocomplete="off">
				<template #prefix>
					<el-icon class="el-input__icon">
						<ele-User />
					</el-icon>
				</template>
			</el-input>
		</el-form-item>
		<el-form-item class="login-animation2">
			<el-input type="password" placeholder="请输入密码" v-model="ruleForm.password" clearable autocomplete="off">
				<template #prefix>
					<el-icon class="el-input__icon">
						<ele-Unlock />
					</el-icon>
				</template>
			</el-input>
		</el-form-item>
		<el-form-item class="login-animation3">
			<el-input type="password" placeholder="请再次输入密码" v-model="ruleForm.againPassword" clearable autocomplete="off">
				<template #prefix>
					<el-icon class="el-input__icon">
						<ele-Unlock />
					</el-icon>
				</template>
			</el-input>
		</el-form-item>
		<el-form-item class="login-animation4">
			<el-button round type="primary" class="login-content-submit" :loading="loading" @click="onRegisterIn">
				<span>注册并登录</span>
			</el-button>
		</el-form-item>
	</el-form>
</template>

<script lang="ts" setup>
import { ref, reactive } from 'vue';
import { ElMessage } from 'element-plus';
// 定义接口来定义对象的类型
interface RegisterState {
	userName: string;
	password: string;
	againPassword: string;
}
// 定义对象与类型
const ruleForm: RegisterState = reactive({
	userName: '',
	password: '',
	againPassword: ''
});
const loading = ref(false);
const onMessageIn = (message: string) => {
	ElMessage.closeAll();
	ElMessage.error(message);
	setTimeout(() => { loading.value = false }, 500);
}
const onRegisterIn = () => {
	loading.value = true;
	const { userName, password, againPassword } = ruleForm;
	if (!userName) { onMessageIn('账号不能为空'); return };
	if (userName.length < 4) { onMessageIn('账号不小于4位'); return };
	if (!password) { onMessageIn('密码不能为空'); return };
	if (password.length < 6) { onMessageIn('密码不小于6位'); return };
	if (password !== againPassword) { onMessageIn('密码不一致'); return };
	loading.value = false
}
</script>

<style scoped lang="scss">
.login-content-form {
	margin-top: 20px;

	@for $i from 1 through 4 {
		.login-animation#{$i} {
			opacity: 0;
			animation-name: error-num;
			animation-duration: 0.5s;
			animation-fill-mode: forwards;
			animation-delay: calc($i/10) + s;
		}
	}

	.login-content-code {
		width: 100%;
		padding: 0;
	}

	.login-content-submit {
		width: 100%;
		letter-spacing: 2px;
		font-weight: 400;
		margin-top: 15px;
	}

}
</style>
